package com.tcm.portal.web.controller;

import com.base.core.utils.R;
import com.tcm.invite.service.InviteService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RequestMapping("/invite")
@RestController
public class InviteController {

    @DubboReference(version = "0.0.1-alpha", timeout = 3000, check = false, retries = 3)
    private InviteService inviteService;

    /**
     * 微信授权后回调获取手机号码
     * @param encryptedData
     * @return
     * @throws Exception
     */
    @GetMapping("/wx/phone")
    public R wxPhone(String encryptedData, String iv, String session_key) throws Exception {
        Map<String, String> rs = inviteService.getPhoneNumber(encryptedData, iv, session_key);
        return R.success(rs);
    }

    /**
     * 小程序授权登录
     * @param code
     * @return
     * @throws Exception
     */
    @GetMapping("/wx/mini/login")
    public R wxMiniLogin(String code) throws Exception {
        Map<String, String> rs = inviteService.miniLogin(code);
        return R.success(rs);
    }

    /**
     * 保存邀请信息
     * @param param
     * @return
     * @throws Exception
     */
    @GetMapping("/port")
    public R saveInviteInfo(String spread,String param) throws Exception {
        try{
            return inviteService.saveInviteInfo(spread, param);
        }catch (Exception e){
            e.printStackTrace();
            return R.fail();
        }

    }



}
